package com.wskh.edu.controller;


import com.wskh.commonUtil.R;
import com.wskh.edu.entity.subject.OneSubject;
import com.wskh.edu.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author wskh
 * @since 2021-10-14
 */
@Api(value = "课程分类管理")
@RestController
@RequestMapping("/eduService/subject")
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,RequestMethod.OPTIONS}) // 允许请求跨域
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    //添加课程分类
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {
        //1 获取上传的excel文件 MultipartFile
        //返回错误提示信息
        subjectService.saveSubject(file,subjectService);
        //判断返回集合是否为空
        return R.ok();
    }

    // 获取所有课程分类
    @ApiOperation(value = "获取所有课程分类")
    @GetMapping("getAllSubject")
    public R nestedList(){
        List<OneSubject> oneSubjectList = subjectService.getAllSubject();
        return R.ok().data("items", oneSubjectList);
    }
}

